/**   
 * @Title: BaseServiceImpl.java 
 * @Package com.leesche.zcsp.center.web.service.impl 
 * @Description:() 
 * @author dennies yang
 * @date 2016年9月21日 下午11:52:48 
 * @version V1.0   
 */
package com.leesche.zcsp.node.web.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.leesche.zcsp.node.utils.web.PagingCondition;
import com.leesche.zcsp.node.utils.web.PagingResult;
import com.leesche.zcsp.node.web.dao.BaseDao;
import com.leesche.zcsp.node.web.service.BaseService;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Title: BaseServiceImpl.java
 * @Package com.leesche.zcsp.center.web.service.impl
 * @Description:()
 * @author dennies yang
 * @date 2016年9月21日 下午11:52:48
 * @version V1.0
 */
/*@Transactional*/
public class BaseServiceImpl<T, S, D extends Serializable, P extends PagingCondition, ID extends Serializable>
		implements BaseService<T, S, D, P, ID> {

	private BaseDao<T, S, D, P, ID> baseDao;

	public BaseDao<T, S, D, P, ID> getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDao<T, S, D, P, ID> baseDao) {
		this.baseDao = baseDao;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.leesche.zcsp.center.web.service.BaseService#countByCriteria(java.
	 * lang.Object)
	 */
	@Override
	@Transactional(propagation= Propagation.NOT_SUPPORTED,readOnly=true)
	public long countByCriteria(S s) {
		// TODO Auto-generated method stub
		return baseDao.countByExample(s);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.leesche.zcsp.center.web.service.BaseService#deleteByCriteria(java
	 * .lang.Object)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public int deleteByCriteria(S s) {
		// TODO Auto-generated method stub
		return baseDao.deleteByExample(s);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.leesche.zcsp.center.web.service.BaseService#deleteByPrimaryKey(java
	 * .io.Serializable)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public int deleteByPrimaryKey(ID id) {
		// TODO Auto-generated method stub
		return baseDao.deleteByPrimaryKey(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.leesche.zcsp.center.web.service.BaseService#insert(java.lang.Object)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public int insert(T t) {
		// TODO Auto-generated method stub
		return baseDao.insert(t);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.leesche.zcsp.center.web.service.BaseService#insertSelective(java.
	 * lang.Object)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public int insertSelective(T t) {
		// TODO Auto-generated method stub
		return baseDao.insertSelective(t);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.leesche.zcsp.center.web.service.BaseService#selectByCriteria(java
	 * .lang.Object)
	 */
	@Override
	@Transactional(propagation= Propagation.NOT_SUPPORTED,readOnly=true)
	public List<Map<String, Object>> selectByCriteria(S s) {
		// TODO Auto-generated method stub
		return baseDao.selectByExample(s);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.leesche.zcsp.center.web.service.BaseService#selectByPrimaryKey(java
	 * .io.Serializable)
	 */
	@Override
	@Transactional(propagation= Propagation.NOT_SUPPORTED,readOnly=true)
	public T selectByPrimaryKey(ID id) {
		// TODO Auto-generated method stub
		return baseDao.selectByPrimaryKey(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.leesche.zcsp.center.web.service.BaseService#updateByCriteriaSelective
	 * (java.lang.Object, java.lang.Object)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public int updateByCriteriaSelective(T t, S s) {
		// TODO Auto-generated method stub
		return baseDao.updateByExampleSelective(t, s);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.leesche.zcsp.center.web.service.BaseService#updateByCriteria(java
	 * .lang.Object, java.lang.Object)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public int updateByCriteria(T t, S s) {
		// TODO Auto-generated method stub
		return baseDao.updateByExample(t, s);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.leesche.zcsp.center.web.service.BaseService#updateByPrimaryKeySelective
	 * (java.lang.Object)
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public int updateByPrimaryKeySelective(T t) {
		// TODO Auto-generated method stub
		return baseDao.updateByPrimaryKeySelective(t);
	}
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public int updateByPrimaryKey(T t) {
		// TODO Auto-generated method stub
		return baseDao.updateByPrimaryKey(t);
	}

	@Override
	public int netUpdateByPrimaryKey(T t) {
		return baseDao.updateByPrimaryKey(t);
	}

	/**
	 * 获取分页数据
	 * @param p 分页条件
	 * @return 分页结果集
	 */
	@Override
	@Transactional(propagation= Propagation.NOT_SUPPORTED,readOnly=true)
	public PagingResult<D> findAllByPage(P p) {
		// TODO Auto-generated method stub
		//p.setPage(p.getPage()-1);
		return new PagingResult<D>(baseDao.selectPageByCriteria(p),
				baseDao.countPageByCriteria(p), p.getPage());
	}


	@Override
	@Transactional(propagation= Propagation.NOT_SUPPORTED,readOnly=true)
	public D findByCondition(P p) {
		// TODO Auto-generated method stub
		return baseDao.selectByCondition(p);
	}

	@Override
	@Transactional(propagation= Propagation.NOT_SUPPORTED,readOnly=true)
	public List<D> findListsByCondition(P p) {
		// TODO Auto-generated method stub
		return baseDao.selectListsByCondition(p);
	}
	
	

}
